﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfControlDemo.依赖属性
{
    /// <summary>
    /// DependencyPropertyWindow.xaml 的交互逻辑
    /// </summary>
    public partial class DependencyPropertyWindow : Window
    {
        public DependencyPropertyWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UserInfo userInfo = new UserInfo(); //数据源对象
            userInfo.UserId = 101;

            Binding bind1 = new Binding("Content"); // 设置要绑定的属性
            bind1.Source = lblInfo;//源对象 // 设置要绑定的控件
            bind1.Mode = BindingMode.OneWay; // 设置绑定的模式
            // 设置数据源绑定的具体值
            BindingOperations.SetBinding(userInfo, UserInfo.UserNameProperty, bind1);

        }
    }
}
